package com.example.administrator.familfinalcialmanagement.ui.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.GreenDaoUtils;
import com.example.administrator.familfinalcialmanagement.bean.PayInfoBean;
import com.example.administrator.familfinalcialmanagement.databinding.ActivityTodayPayBinding;
import com.example.administrator.familfinalcialmanagement.greendao.gen.PayInfoBeanDao;
import com.example.administrator.familfinalcialmanagement.ui.BaseActivity;
import com.example.administrator.familfinalcialmanagement.ui.adapter.PayAdapter;
import com.example.administrator.familfinalcialmanagement.util.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SensYang on 2019/04/02 1:44
 */

public class TodayPayActivity extends BaseActivity {

    ActivityTodayPayBinding binding;
    List<PayInfoBean> list = new ArrayList<>();
    PayInfoBeanDao daobeanDao = GreenDaoUtils.getSingleTon().getmDaoSession().getPayInfoBeanDao();
    PayAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_today_pay);
        binding.setActivity(this);
        initView();
    }

    private void initView() {
        setTitleText("今日账务");
        setBack();

        list.clear();
        list = daobeanDao.loadAll();
        binding.recycler.setLayoutManager(new LinearLayoutManager(this));
        adapter = new PayAdapter(this, list);
        binding.recycler.setAdapter(adapter);
        adapter.setOnItemClickLitener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(TodayPayActivity.this, TodayPayDescActivity.class);
                intent.putExtra("module_title",list.get(position).getTitle());
                intent.putExtra("module_info",list.get(position).getInfo());
                intent.putExtra("module_status",list.get(position).getPayStatus());
                intent.putExtra("module_style",list.get(position).getPayStyle());
                intent.putExtra("module_money",list.get(position).getMoney());
                intent.putExtra("module_time",list.get(position).getPayTime());
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

    }
}
